import { defineStore } from "pinia";
import { getRoute } from "@/api/menuRoute";
import { getSession, setSession } from "@/utils/storage";

export const useRouteStore = defineStore("ROUTE", {
  state: () => {
    return {
      menuRouteRaw: getSession("__menuRoute__", []),
    //   menuRouteRaw: [],
    };
  },
  actions: {
    getMenuRouteFn() {
      getRoute().then(({ data }) => {
        this.menuRouteRaw = data;
        setSession("__menuRoute__", data);
      });
    },
  },
  getters: {
    menuRoute() {
      return this.menuRouteRaw.length? this.menuRouteRaw: [
            {
              children: [],
              icon: "user",
              path: "/profile",
              title: "个人中心",
            },
          ];
    },
  },

  // persist: {
  //     enabled: true,
  //     strategies: [{Storage: localStorage, path: ["menuRoute"]}],
  // },
});
